package com.code;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 生成mybatis文件
 * 
 * @author mayt
 */
public class CodeGeneratorMain {

    private static final Logger LOGGER = LoggerFactory.getLogger(CodeGeneratorMain.class);

    /** 配置文件路径 */
    public static final String CFG_FILE_PATH = CodeGeneratorMain.class
            .getResource("/mybatis/generator/generatorConfig.xml").getFile();

    public static void main(String[] args) throws Exception {
        List<String> warnings = new ArrayList<>();
        boolean overwrite = true;
        File configFile = new File(CFG_FILE_PATH);
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = null;
        config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = null;
        myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
        for (String warning : warnings) {
            System.out.println(warning);
        }
        LOGGER.info("gen end");
    }
}
